package com.peppa.controller;

import com.peppa.controller.fronted.MainPageController;
import com.peppa.controller.superadmin.HeadLineOperationController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//拦截所有请求
//解析请求
//派发对应的Controller里面的方法进行处理
@WebServlet("/")
public class DispatchServlet  extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("request path is: "+req.getServletPath());
        System.out.println(req.getMethod());
        if(req.getServletPath()=="/fronted/getmainpageinfo"&&req.getMethod()=="GET"){
            new MainPageController().getMainPageInfo(req,resp);
        }else if(req.getServletPath()=="/superadmin/addheadline"&&req.getMethod()=="POST"){
            new HeadLineOperationController().addHeadLine(req,resp);
        }
    }
}
